https://leetcode.cn/problems/number-of-islands/
class Solution {
public:
    typedef pair<int,int> PII;
    
    int dx[4]={0,0,1,-1};
    int dy[4]={1,-1,0,0};
    
    bool visited[301][301];

    int m,n;

    //bfs将周围的陆地包含
    void bfs(vector<vector<char>>& grid,int sr,int sc)
    {
        queue<PII> q;
        q.push({sr,sc});
        visited[sr][sc]=true;
        while(!q.empty())
        {
            auto [a,b]=q.front();
            q.pop();
            for(int i=0;i<4;i++)
            {
                int x=a+dx[i],y=dy[i]+b;
                if(x>=0&&x<m&&y>=0&&y<n&&visited[x][y]==false&&grid[x][y]=='1')
                {
                    q.push({x,y});
                    visited[x][y]=true;
                }
            }
        }
    }

    int numIslands(vector<vector<char>>& grid) {
        m=grid.size(),n=grid[0].size();
        int ret=0;
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<n;j++)
            {
                if(grid[i][j]=='1'&&visited[i][j]==false)
                {
                    ret++;
                    bfs(grid,i,j);
                }
            }
        } 
        return ret;
    }
};